package org.example.cloudprviderpayment8001.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.example.cloudprviderpayment8001.mapper.StudentMapper;
import org.example.cloudprviderpayment8001.pojo.Student;
import org.example.cloudprviderpayment8001.util.BaseResult;
import org.example.cloudprviderpayment8001.util.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/usr")
@RestController
public class Login {

    @Autowired
    private StudentMapper studentMapper;

    @GetMapping("/login")
    public BaseResult login(@RequestParam("username") String username,@RequestParam("password") String password){
        System.out.println(username+password);
        QueryWrapper<Student> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username",username);
        queryWrapper.eq("password",password);
        Student student = studentMapper.selectOne(queryWrapper);
        String token = JwtUtils.getToken(student.getName());
        boolean verify = JwtUtils.verify(token);
        return BaseResult.ok(token);
    }

    @GetMapping("/login1")
    public BaseResult login1(){
        return BaseResult.ok("11");
    }
}
